package day01;

import java.util.Arrays;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/2/28 10:19
 */
public class BubbleSortRecursion {
    public static void main(String[] args) {
        int[] arr = { 2, 5, 1, 3, 7, 4};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr) {
        bubbleSort(arr, arr.length - 1);
    }

    public static void bubbleSort(int[] arr, int j) {
        if (j == 0) {
            return;
        }
        int x = 0;
        for (int i = 0; i < j; i++) {
            if (arr[i] > arr[i+1]) {
                // x是右边界 无序和有序的分界线
                x = i;
                int temp = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = temp;
            }
        }
        bubbleSort(arr, x);
    }
}
